package cn.itcast.users.mapper;


import cn.itcast.users.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    /**
     * 根据openid获取用户信息
     *
     * @param openid
     * @return
     */
    User getByOpenid(String openid);


    /**
     * 新增用户
     *
     * @param user
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into user(openid, name, phone, sex, id_number, avatar, create_time)" +
            " values(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber},#{avatar},#{createTime})")
    void insert(User user);

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getById(Long id);

    /**
     * 根据创建时间统计用户数量
     * @param map
     * @return
     */
    Integer getUserReportByMap(Map<String, Object> map);

    /**
     * 批量获取新增用户数
     * @param map
     * @return
     */
    @MapKey("")
    List<Map<String, Object>> getUserReportByList(Map<String, Object> map);
}
